package com.orcs.leefei.utils.kotlin

import android.os.Build

/**
 * Created by FeiLee on 2016/12/26 11:16.
 */

fun beforeNougat(action:()->Unit = {}): Boolean = isOlderVersionThen(24, action)
fun nougatOrNewer(action:()->Unit = {}): Boolean= isOnVersionOrNewer(24, action)
fun beforeMarshmallow(action:()->Unit = {}): Boolean = isOlderVersionThen(23, action)
fun marshmallowOrNewer(action:()->Unit = {}): Boolean= isOnVersionOrNewer(23, action)
fun beforeLollipop(action:()->Unit = {}): Boolean = isOlderVersionThen(21, action)
fun lollipopOrNewer(action:()->Unit = {}): Boolean = isOnVersionOrNewer(21, action)
fun beforeKitkat(action:()->Unit = {}): Boolean = isOlderVersionThen(19, action)
fun kitkatOrNewer(action:()->Unit = {}): Boolean = isOnVersionOrNewer(19, action)
fun beforeJellyBean(action:()->Unit = {}): Boolean = isOlderVersionThen(16, action)
fun jellyBeanOrNewer(action:()->Unit = {}): Boolean = isOnVersionOrNewer(16, action)
fun beforeIcs(action:()->Unit = {}): Boolean = isOlderVersionThen(14, action)
fun icsOrNewer(action:()->Unit = {}): Boolean = isOnVersionOrNewer(14, action)
fun beforeVersion(version: Int, action:()->Unit)= isOlderVersionThen(version, action)
fun versionOrNewer(version: Int, action:()->Unit) = isOnVersionOrNewer(version, action)
fun currentVersion(): Int = Build.VERSION.SDK_INT

/*
 * -----------------------------------------------------------------------------
 *  Private methods
 * -----------------------------------------------------------------------------
 */
private fun isOlderVersionThen(version: Int, action:()->Unit):Boolean{
    if (Build.VERSION.SDK_INT< version ){
        action()
        return true
    }
    
    return false
}

private fun isOnVersionOrNewer(version: Int,action:()->Unit):Boolean{
    if(Build.VERSION.SDK_INT>=version){
        action()
        return true
    }

    return false
}
